/**
 * 标准售后服务收费项目维护
 * @author mengyb
 * @date 2019-04-17
 */
define(function () {

    var self,
        app = win.app,
        doc = document,
        layui = win.layui,
        table,
        table_where = {},
        element,
        vueData = {},
        cols = [[
            {type:'checkbox',title:'选择',width:60,fixed:'left'},
            {field:'ROW_ID',title:'序号',width:60,fixed:'left'},
            {field:'MMRC001',title:'收费项目编号',width:120,fixed:'left',sort:true,search:'default'},
            {field:'MMRCL003',title:'说明',width:80,sort:true,search:'default'},
            {field:'MMRCL004',title:'助记码',width:80,sort:true,search:'default'},
            {field:'MMRCACTI',title:'有效',width:80,filterDatas:app.datas_('sys_y_n'),sort:true},
            {title:'',width:60,toolbar:'#script-gwai630setting',fixed:'right',align:'center',unresize:true}

        ]],

        gwai630SettingAction,
        moduleName = "标准售后服务收费项目",
        editArea = ['400px', '380px'];


    var Gwai630 = app.Module.extend({

        init: function () {
            self=this;
            self._super({
                _tag: 'gwai630',
                _searchs:[
                    {id:'gwai630',tableId:'gwai630_table',datas:cols[0]}
                ],
                _loadTplsFull:[
                    {dom:'gwai630_edit',tpl:'base/gwai630_edit'}
                ]
            }, win);
        },

        initTable: function () {
            layui.use(['table'], function () {
                table = layui.table;
                table.render({
                    elem: app.getByid(doc, 'gwai630_table'),
                    url: g_ctxPath + 'base/gwai630/getList',
                    method: 'post',
                    id: 'gwai630_table',
                    title: moduleName+'表',
                    size: _layuiConfig.ui_size,
                    autoSort: false, //禁用前端自动排序
                    toolbar: '#table-toolbar',
                    defaultToolbar: ['filter', 'exports'],
                    height: 'full',
                    cols: cols,
                    loading: true,//是否显示加载条
                    page: true,
                    where: table_where,
                    done: function (res, curr, count) {

                    }
                });

                layui.laytpl(app.getByid(doc, 'script-gwai630setting-action').innerHTML).render({}, function (string) {
                    gwai630SettingAction = string;
                });

                //弹出层索引
                var tipsIndex=null;


                //监听行工具栏事件，弹出编辑与删除按钮 lay-filter指定
                table.on('tool(gwai630_table)', function (obj) {
                    layer.tips(gwai630SettingAction, obj.td, {
                        tips: [3, '']
                        , time: 3000
                        , anim: 500
                        , maxWidth: 120
                        , skin: 'layui-table-tips'
                        , success: function (layero, index) {
                            tipsIndex = index;
                            layero.find('li').on('click', function () {
                                switch ($(this).attr('inx')) {
                                    case '1':
                                        self._openTplFull({
                                            tag: 'gwai630_edit',
                                            tagData: {
                                                isAdd:false,
                                                obj : obj,
                                                moduleName : moduleName
                                            },
                                            index: 0,
                                            openOpts: {
                                                title: '修改'+moduleName+'信息',
                                                area:editArea
                                            }
                                        });
                                        break;
                                    case '2':
                                        self.delRow(obj);
                                        break;
                                }
                                layer.close(index);
                                tipsIndex = null;
                            });
                        }
                    });
                    return false;

                });

                //监听表头工具栏事件
                table.on('toolbar(gwai630_table)', function (obj) {
                    var checkStatus = table.checkStatus('gwai630_table');
                    switch (obj.event) {
                        case 'add':
                            self._openTplFull({
                                tag: 'gwai630_edit',
                                tagData: {
                                    isAdd: true,
                                    moduleName:moduleName
                                },
                                index: 0,
                                openOpts: {
                                    title: '新增'+moduleName+'信息',
                                    area:editArea
                                }
                            })
                            break;
                        case 'del':
                            self.delRows(checkStatus);
                            break;
                    }

                });

                //关闭弹出层
                $(doc).on('click', function () {
                    tipsIndex && layer.close(tipsIndex);
                });

                //监听行双击事件
                table.on('rowDouble(gwai630_table)',function (obj) {
                    self._openTplFull({
                        tag:'gwai630_edit',
                        tagData: {
                            obj:obj,
                            isAdd:false,
                            moduleName:moduleName,
                            is_detail: true
                        },
                        index:0,
                        openOpts:{
                            title: '修改'+moduleName+'信息',
                            area:editArea
                        }
                    })
                })

            });
        },

        reloadTableCurr: function () {
            self._reloadTable({id: 'gwai630_table', where: table_where});
        },

        delRow:function (obj) {
            app.confirm({
                msg:'确认删除该条信息吗？',
                ok: function () {
                    app.ajax({
                        xurl:'base/gwai630/delRow',
                        xdata:obj.data,
                        loading:true,
                        okmsg:moduleName+'信息删除成功',
                        cb: function (result) {
                            if (result.ok) {
                                self.reloadTableCurr();
                            }
                        }
                    })

                }
            })
        },

        delRows:function (checkStatus) {
            if(checkStatus.data.length>0){
                var _xdata = [];
                checkStatus.data.forEach(function (value) {
                    var _temp={};
                    _temp.MMRCENT=value.MMRCENT;
                    _temp.MMRC001=value.MMRC001;
                    _xdata.push(_temp);
                });
                app.confirm({
                    msg:'确认删除所选择的信息吗？',
                    ok: function () {
                        app.ajax({
                            xurl:'base/gwai630/delRows',
                            xdata:_xdata,
                            toJsonStr:true,
                            okmsg:moduleName+'信息删除成功',
                            loading:true,
                            cb: function (result) {
                                if (result.ok) {
                                    self.reloadTableCurr();
                                }
                            }
                        })

                    }
                })

            }else{

                app.showMessage("请先选择待删除的信息！")
            }
        },

        _ready: function () {
            vueData.serchData=table_where;
            this._super({
               vue:[{
                   el: '#page',
                   id: 'page',
                   data: vueData,
                   searchId: 'gwai630',
                   methods:{}
               }]

            });
            self.initTable();
        },

        _lazy: function () {
            this._super();
            layui.use(['table'], function () {
                element=layui.element;
            });
        }



    });

    return new Gwai630();


});